home *** CD-ROM | disk | FTP | other *** search
/ Collection of Tools & Utilities / Collection of Tools and Utilities.iso / edit / mg2a_src.zip / MAIN.C < prev    next >
C/C++ Source or Header  |  1988-08-23  |  3KB  |  144 lines

  1. /*
  2.  *        Mainline
  3.  */
  4. #include    "def.h"
  5. #ifndef NO_MACRO
  6. #include    "macro.h"
  7. #endif
  8.  
  9. int    thisflag;            /* Flags, this command        */
  10. int    lastflag;            /* Flags, last command        */
  11. int    curgoal;            /* Goal column            */
  12. BUFFER    *curbp;                /* Current buffer        */
  13. WINDOW    *curwp;                /* Current window        */
  14. BUFFER    *bheadp;            /* BUFFER listhead        */
  15. WINDOW    *wheadp = (WINDOW *)NULL;    /* WINDOW listhead        */
  16. char    pat[NPAT];            /* Pattern            */
  17. #ifndef NO_DPROMPT
  18. extern char prompt[], *promptp;        /* delayed prompting        */
  19. #endif
  20.  
  21. static VOID    edinit();
  22.  
  23. VOID
  24. main(argc, argv)
  25. int  argc;
  26. char **argv;
  27. {
  28. #ifndef NO_STARTUP
  29.     char    *startupfile();
  30. #endif
  31.     char    *cp;
  32.     VOID    vtinit(), makename(), eerase();
  33.     BUFFER    *findbuffer();
  34.  
  35. #ifdef SYSINIT
  36.     SYSINIT;                /* system dependent.    */
  37. #endif
  38.     vtinit();                /* Virtual terminal.    */
  39. #ifndef NO_DIR
  40.     dirinit();                /* Get current directory */
  41. #endif
  42.     edinit();                /* Buffers, windows.    */
  43.     ttykeymapinit();            /* Symbols, bindings.    */
  44.     /* doing update() before reading files causes the error messages from
  45.      * the file I/O show up on the screen.    (and also an extra display
  46.      * of the mode line if there are files specified on the command line.)
  47.      */
  48.     update();
  49. #ifndef NO_STARTUP                /* User startup file.    */
  50.     if ((cp = startupfile((char *)NULL)) != NULL)
  51.         (VOID) load(cp);
  52. #endif
  53.     while (--argc > 0) {
  54.         cp = adjustname(*++argv);
  55.         curbp = findbuffer(cp);
  56.         (VOID) showbuffer(curbp, curwp, 0);
  57.         (VOID) readin(cp);
  58.     }
  59.     thisflag = 0;                /* Fake last flags.    */
  60.     for(;;) {
  61. #ifndef NO_DPROMPT
  62.         *(promptp = prompt) = '\0';
  63.         if(epresf == KPROMPT) eerase();
  64. #endif
  65.         update();
  66.         lastflag = thisflag;
  67.         thisflag = 0;
  68.         switch(doin()) {
  69.         case TRUE: break;
  70.         case ABORT:
  71.             ewprintf("Quit");        /* and fall through    */
  72.         case FALSE:
  73.         default:
  74.             ttbeep();
  75. #ifndef NO_MACRO
  76.             macrodef = FALSE;
  77. #endif
  78.         }
  79.     }
  80. }
  81.  
  82. /*
  83.  * Initialize default buffer and window.
  84.  */
  85. static VOID
  86. edinit() {
  87.     register BUFFER *bp;
  88.     register WINDOW *wp;
  89.  
  90.     bheadp = NULL;
  91.     bp = bfind("*scratch*", TRUE);        /* Text buffer.        */
  92.     wp = (WINDOW *)malloc(sizeof(WINDOW));    /* Initial window.    */
  93.     if (bp==NULL || wp==NULL) panic("edinit");
  94.     curbp  = bp;                /* Current ones.    */
  95.     wheadp = wp;
  96.     curwp  = wp;
  97.     wp->w_wndp  = NULL;            /* Initialize window.    */
  98.     wp->w_bufp  = bp;
  99.     bp->b_nwnd  = 1;            /* Displayed.        */
  100.     wp->w_linep = wp->w_dotp = bp->b_linep;
  101.     wp->w_doto  = 0;
  102.     wp->w_markp = NULL;
  103.     wp->w_marko = 0;
  104.     wp->w_toprow = 0;
  105.     wp->w_ntrows = nrow-2;            /* 2 = mode, echo.    */
  106.     wp->w_force = 0;
  107.     wp->w_flag  = WFMODE|WFHARD;        /* Full.        */
  108. }
  109.  
  110. /*
  111.  * Quit command. If an argument, always
  112.  * quit. Otherwise confirm if a buffer has been
  113.  * changed and not written out. Normally bound
  114.  * to "C-X C-C".
  115.  */
  116. /*ARGSUSED*/
  117. quit(f, n)
  118. {
  119.     register int    s;
  120.     VOID        vttidy();
  121.  
  122.     if ((s = anycb(FALSE)) == ABORT) return ABORT;
  123.     if (s == FALSE
  124.     || eyesno("Some modified buffers exist, really exit") == TRUE) {
  125.         vttidy();
  126. #ifdef    SYSCLEANUP
  127.     SYSCLEANUP;
  128. #endif
  129.         exit(GOOD);
  130.     }
  131.     return TRUE;
  132. }
  133.  
  134. /*
  135.  * User abort. Should be called by any input routine that sees a C-g
  136.  * to abort whatever C-g is aborting these days. Currently does
  137.  * nothing.
  138.  */
  139. /*ARGSUSED*/
  140. ctrlg(f, n)
  141. {
  142.     return ABORT;
  143. }
  144.